package com.stephenone.zhdaily.comment;

import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;

import com.stephenone.zhdaily.Constants;
import com.stephenone.zhdaily.R;
import com.stephenone.zhdaily.data.source.CommentsRepository;
import com.stephenone.zhdaily.data.source.remote.CommentsRemoteDataSource;
import com.stephenone.zhdaily.uitl.ActivityUtils;

public class CommentActivity extends AppCompatActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_comment);

        long id = getIntent().getLongExtra(Constants.KEY_STORY_ID,0);

        // Set up the toolbar.
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        ActionBar ab = getSupportActionBar();
        ab.setDisplayHomeAsUpEnabled(true);
        ab.setDisplayShowHomeEnabled(true);

        CommentFragment commentFragment = (CommentFragment) getSupportFragmentManager()
                .findFragmentById(R.id.contentFrame);

        if (commentFragment == null) {
            commentFragment = CommentFragment.newInstance(id);

            ActivityUtils.addFragmentToActivity(getSupportFragmentManager(),
                    commentFragment, R.id.contentFrame);
        }

        new CommentPresenter(CommentsRepository.getInstance(CommentsRemoteDataSource.getInstance()),commentFragment,id);
    }

    @Override
    public boolean onSupportNavigateUp() {
        onBackPressed();
        return true;
    }
}
